package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgStore;
import  com.ygqh.baby.mapper.YgStoreMapper;
import  com.ygqh.baby.service.YgStoreService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgStoreExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgStoreServiceImpl implements YgStoreService{
	
	@Autowired
	private YgStoreMapper ygStoreMapper;
	
	@Override
	public List<YgStore> find() {
		YgStoreExample example = new YgStoreExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygStoreMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgStoreExample example = new YgStoreExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygStoreMapper.countByExample(example);
	}

	@Override
	public YgStore findById(Long id) {
		return ygStoreMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgStore ygStore) {
		return ygStoreMapper.insertSelective(ygStore);
	}

	@Override
	public int update(YgStore ygStore) {
		return ygStoreMapper.updateByPrimaryKeySelective(ygStore);
	}

	@Override
	public ResultSet<YgStore> search(QueryInfo queryInfo,String q) {
		List<YgStore>  list =  ygStoreMapper.selectSuper(queryInfo, q);
		int count = ygStoreMapper.countSuper(q);
		ResultSet<YgStore> resultSet = new ResultSet<YgStore>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgStoreExample example = new YgStoreExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgStore record = new YgStore();
		record.setStatus(DataStatus.Delete);

		return ygStoreMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgStore ygStore) {
		int r = 0;
		if(ygStore.getId() != null) {
			r = this.update(ygStore);
		}else {
			r = this.save(ygStore);
		}
		return r;
	}

}

